
var express = require('express');
var router = new express.Router();
var Mock = require('mockjs')
var users=[];
var list = Mock.mock({
  'list|3': [{
    'id|+1':1,
    name:'@name',
    age:'@natural(18,80)',
    'permission|1':['系统管理','普通管理'],
    'phoneNumber': /\d{6,10}/,
    address:'@county(true)',
    datetime:'@datetime'
  }]
})

users=list.list;

router.get('/list', function (req, res) {



  res.send(list.list);
})
/*var employees=require('.data/employee')*/


router.get('/add',function (request,response) {
  console.log(request.query);
  if(request.query.id==-1){
    users.unshift(request.query)
  }else {

  }
  response.send({
    emps:users,
    flag: true
  })
})




var user=[{
  username: 'admin',
  password: '123456'
},{
  username:'test',
  password:'test'
}];
router.get('/login',function (req,res) {
  var loginUser = {
    username: req.query.username,
    password: req.query.password
  }
  var foundUser = user.find(function (user) {
    return user.username == loginUser.username && user.password == loginUser.password;

  })
  if (foundUser) {
    res.send({
      flag: true
    })
  } else {
    res.send({
      flag: false
    })
  }
})

module.exports = router;

